package perform.criterion;

public class Or extends AbstractCriterion {
	
	private Or(StringBuilder builder){
		super(builder);
	}
	
	public static Or create(Criterion criterion1, Criterion criterion2){
		StringBuilder builder = new StringBuilder();
		builder.append(process(criterion1)).append(" or ").append(process(criterion2));
		return new Or(builder);
	}
	
	private static String process(Criterion criterion){
		if(criterion instanceof And || criterion instanceof Or){
			return "( " + criterion.toString() + " )";
		} else {
			return criterion.toString();
		}
	}
	
	public Or add(Criterion criterion){
		builder.append(" or ").append(process(criterion));
		return this;
	}

}
